package leetcodecompetition.D367;

/**
 * @Author: Siantar
 * @Date: 2023-10-15-10:44
 * @Description: 1.0
 */
public class T100101 {
    public int[] findIndices(int[] nums, int indexDifference, int valueDifference) {
        int n = nums.length;
        if (n - 1 < indexDifference) return new int[]{-1, -1};
        int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE;
        int minIndex = -1, maxIndex = -1;
        for (int i = indexDifference; i < n; i++) {
            int d = i - indexDifference;
            if (nums[d] < min) {
                min = nums[d];
                minIndex = d;
            }
            if (nums[d] > max) {
                max = nums[d];
                maxIndex = d;
            }
            if (Math.abs((long)min - nums[i]) >= valueDifference) {
                return new int[]{minIndex, i};
            }
            if (Math.abs((long)max - nums[i]) >= valueDifference) {
                return new int[]{maxIndex, i};
            }
        }
        return new int[]{-1, -1};
    }
}
